//
//  OpinionViewController.m
//  B2C
//
//  Created by 李小龙 on 2017/8/1.
//  Copyright © 2017年 lixiaolong. All rights reserved.
//

#import "OpinionViewController.h"

@interface OpinionViewController ()
@property (weak, nonatomic) IBOutlet SZTextView *textView;

@end

@implementation OpinionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"意见反馈";
    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonAction:)];
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIColor colorWithHex:0x030303 alpha:1.0] forKey:NSForegroundColorAttributeName];
    [right setTitleTextAttributes:dic forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = right;
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.textView becomeFirstResponder];
}
- (void)rightBarButtonAction:(id)sender {
    NSLog(@"提交");
    if (!TextIsNotNil(_textView.text)) {
        [MBProgressHUD myShowHUDAddedTo:self.view labelText:@"请输入您的反馈意见" animated:YES];
        return;
    }
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    //    [self startLoadingGifView];
    __weak typeof(self) weakSelf = self;
    [MYAFNetworking POST:URL_Save_Feedback parameters:@{@"fcontent":_textView.text} success:^(NSURLSessionDataTask *task, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        NSDictionary *dics = responseObject;
        
        if ([[dics objectForKey:@"code"] isEqualToString:@"200"]) {
            [MBProgressHUD myShowHUDAddedTo:self.view labelText:@"提交成功" animated:YES];
            
            [weakSelf disMissSelf];
        } else {
            
            [MBProgressHUD showError:weakSelf.view title:dics[@"message"] code:[dics objectForKey:@"code"] animated:YES];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [MBProgressHUD showError:weakSelf.view title:@"" code:@"" animated:YES];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
